package com.rr.controller;

import com.rr.service.LocalCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cache")
@RequiredArgsConstructor
public class LocalCacheController {

    private final LocalCacheService localCacheService;

    @PostMapping("/put")
    public String put(@RequestParam("instanceName") String instanceName, @RequestParam("key") String key,
        @RequestParam("value") String value) {
        localCacheService.put(instanceName, key, value);
        return "ok";
    }

    @GetMapping("/get")
    public String get(@RequestParam("instanceName") String instanceName, @RequestParam("key") String key) {
        return localCacheService.get(instanceName, key);
    }

    @GetMapping("/invalidateAll")
    public String invalidateAll(@RequestParam("instanceName") String instanceName) {
        localCacheService.invalidateAll(instanceName);
        return "ok";
    }

}
